package com.canbot.u05.control;

import android.text.TextUtils;

/**
 * Created by Administrator on 2017/5/8.
 */

public class DataUtil {

    public static String formatTime(int time) {
        int minute = time / 60;
        int second = time % 60;
        String minuteStr;
        String secondStr;
        if (minute < 10) {
            minuteStr = String.format("0%d", minute);
        } else {
            minuteStr = String.format("%d", minute);
        }
        if (second < 10) {
            secondStr = String.format("0%d", second);
        } else {
            secondStr = String.format("%d", second);
        }
        return String.format("%s:%s", minuteStr, secondStr);
    }

    public static int getTtsTime(String content) {
        if (TextUtils.isEmpty(content)) {
            return 0;
        } else {
            int length = content.length();
            int time = (int) (length * 0.3);
            if (time <= 0) {
                time = 1;
            }
            return time;
        }
    }

    public static final String bytesToHexString(byte[] bArray) {
        StringBuffer sb = new StringBuffer(bArray.length);
        String sTemp;
        for (int i = 0; i < bArray.length; i++) {
            sTemp = Integer.toHexString(0xFF & bArray[i]);
            if (sTemp.length() < 2)
                sb.append(0);
            sb.append(sTemp.toUpperCase() + ", ");
        }
        return sb.toString();
    }
}
